package com.ibeeking.found.cop.b.rest.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ibeeking.found.cop.b.rest.service.ICopPublicParamService;
import com.ibeeking.found.cop.service.common.dos.CopPublicParamDO;

import com.ibeeking.found.cop.service.mapper.CopPublicParamMapper;
import com.ibeeking.nematos.utils.id.IdGenerator;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @ClassName CopChannelServiceImpl
 * @Description
 * @Author ibeeking
 * @Date 2021-01-27 18:50
 **/
@Service
public class CopPublicParamServiceImpl extends ServiceImpl<CopPublicParamMapper, CopPublicParamDO> implements ICopPublicParamService {

    @Resource
    private CopPublicParamMapper copPublicParamMapper;

    @Override
    public Boolean updateOrSave(String paramName, String paramValue) {
        CopPublicParamDO copPublicParamDO = copPublicParamMapper.selectOne(new LambdaQueryWrapper<CopPublicParamDO>().eq(CopPublicParamDO::getParamName, paramName));
        if(copPublicParamDO!=null) {
            copPublicParamDO.setParamValue(paramValue);
            copPublicParamMapper.updateById(copPublicParamDO);
        }else{
            copPublicParamDO = new CopPublicParamDO(IdGenerator.getId(), paramName, paramValue);
            copPublicParamMapper.insert(copPublicParamDO);
        }
        return true;
    }

    @Override
    public String getParamValue(String paramName) {
        CopPublicParamDO copPublicParamDO = copPublicParamMapper.selectOne(new LambdaQueryWrapper<CopPublicParamDO>().eq(CopPublicParamDO::getParamName, paramName));
        if(copPublicParamDO!=null) {
            return copPublicParamDO.getParamValue();
        }else{
            return null;
        }
    }
}
